package cm.tl.pms.common.type;


import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class GeomPointTypeHandler extends BaseTypeHandler<GeomPoint> {
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, GeomPoint parameter, JdbcType jdbcType) throws SQLException {
        ps.setString(i, parameter.toString());
    }

    @Override
    public GeomPoint getNullableResult(ResultSet rs, String columnName) throws SQLException {
        String columnValue = rs.getString(columnName);
        return new GeomPoint().parse(columnValue);
    }

    @Override
    public GeomPoint getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        String columnValue = rs.getString(columnIndex);
        return new GeomPoint().parse(columnValue);
    }

    @Override
    public GeomPoint getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        String columnValue = cs.getString(columnIndex);
        return new GeomPoint().parse(columnValue);
    }
}